<template>
	<view class="ikz-bid">
		<ikz-loading :css-data="loading_css"></ikz-loading>
		<view class="ikz-top-bg">
			<image class="ikz-top-bg-img" :src="service_img"></image>
		</view>
		<!-- ad -->
		<!-- list -->
		<view>
			<ikz-glist :show-type="type_list" :show-data="show_info" :more-status="load_more" @returnId="returnId" :receiver="isReceiver">
			</ikz-glist>
		</view>
		<!-- 缺省 -->
		<view class="default-height" style="width: 100%;height: 92rpx;"></view>
		<ikz-tabbar :show-data="tabbar_Data"></ikz-tabbar>
	</view> 
</template> 

<script> 
	import ikzLoading from '@/pages/Component/Public/Loading/loading.vue';
	import ikzGlist from '@/pages/Component/Public/Glist/public/glist/glist.vue';
	import ikzTabbar from '@/pages/Component/Public/tab-bar/tab-bar.vue';
	var app = getApp();
	import ikz from '@/pages/Common/tools.js';
	export default {
		components: {
			ikzLoading,
			ikzGlist,
			ikzTabbar
		},
		data() {
			return {
				show_info: {
					list: []
				},
				type_list: {
					list: []
				},
				loading_css: {
					display: 'flex'
				},
				service_img:app.globalData.service_img,
				page: 1,
				limit: 10,
				load_more: 5,
				order_type: '',
				show_status: '2',
				tabbar_Data: {
					type: 0,
					list: []
				},
				// 是否为接单员
				isReceiver:0
			};
		},
		created() {},
		onLoad() {
			uni.hideTabBar()
		},
		onPullDownRefresh() {
			this.page = 1;
			this.listInfo((res) => {
				uni.stopPullDownRefresh();
			});
		},
		onReachBottom() {
			if (this.load_more == 2) {
				this.page++;
				this.load_more = 3;
				this.listInfo((res) => {});
			}
		},
		onShow() {
			if(uni.getStorageSync('local_user_session')) {
				this.tabbar_Data.list = app.globalData.tabBarInfo
				this.tabbar_Data.type =  app.globalData.tabBarInfo.length - 2
				if (this.show_status == 2) {
					this.page = 1;
					this.typeInfo();
					this.show_status = 3;
				} else {
					this.page = 1;
					this.listInfo((res) => {});
				}
				this.handleReceiver()
			}else{
				uni.redirectTo({
					url:"/pages/login/index"
				})
			}	
		},
		onShareTimeline() {

		},
		onShareAppMessage() {
			// const promise = new Promise(resolve => {
			//   setTimeout(() => {
			//     resolve({ 
			//       title: '自定义转发标题',
			//       imageUrl:'https://xybaddon.maiwd.cn/shareButton.png',
			//     })
			//   }, 2000)
			// })
			return {
				title: app.globalData.share_info.share_title,
				path: '/pages/Home/index',
				imageUrl: app.globalData.share_info.share_img,
			}
		},
		methods: {
			// 判断是否是接单员
			handleReceiver() {
				var path = '/xyb/user/is_receiver';
				var url = app.globalData.adminPath + path;
				var data = {
					app_plat: "MP-WEIXIN",
					token: uni.getStorageSync('local_user_session'),
					agent_id: uni.getStorageSync('default_agent').id||''
				}
				if(data.token){
					uni.request({
						url: url,
						header: {
							"Content-Type": "application/x-www-form-urlencoded"
						},
						data: data,
						method: 'POST',
						success: (res)=> {
							console.log("是否为接单员",res.data.data.is_receiver);
							uni.setStorageSync('receivers', res.data.data.is_receiver)
							this.isReceiver=res.data.data.is_receiver
						},
						fail: function(res) {
							//调用接口失败或回传失败
							// uni.showModal({
							// 	title: '服务器繁忙',
							// 	content: '服务器繁忙或网络不稳定，请稍后再试！'
							// })
						},
					})
				}
			},
			returnId(e) {
				this.order_type = e;
				this.page = 1;
				this.listInfo((res) => {});
			},
			//分类
			typeInfo() {
				var path = '/xyb/server/list';
				ikz.post(path, {}, res => {
					if (res.data.code) {
						this.type_list.list = res.data.data;
						// this.order_type = res.data.data[0].id
						this.listInfo((res) => {});
						this.$forceUpdate();
					} else {
						uni.showModal({
							title: '提示',
							content: res.data.msg,
							showCancel: false,
							success: function(res) {}
						});
					}
				})
			},
			listInfo(fn) {
				this.loading_css.display = 'flex';
				var path = '/xyb/mp_weixin_home/server_list';
				var data = {
					page: this.page,
					limit: this.limit,
					order_type: this.order_type
				}
					ikz.post(path, data, res => {
						if (res.data.code) {
							var temp_list = res.data.data.data;
							if (this.page != 1) {
								for (var i = 0; i < temp_list.length; i++) {
									this.show_info.list.push(temp_list[i]);
								}
							} else {
								this.show_info.list = temp_list;
							}
							if (temp_list.length == this.limit) {
								this.load_more = 2;
							} else {
								if (this.page == 1) {
									if (temp_list.length == 0) {
										this.load_more = 5;
									} else {
										this.load_more = 4;
									}
								} else {
									this.load_more = 4;
								}
							}
							this.$forceUpdate();
						} else {
							uni.showModal({
								title: '提示',
								content: res.data.msg,
								showCancel: false,
								success: function(res) {}
							});
						}
						this.loading_css.display = 'none';
						fn();
					})
				
				

			},
			goApply() {
				var path = '/pages/Component/Module/Receiver/Program/apply/index/index';
				ikz.nav(path, 'n', '');
			},
			showTreaty() {
				this.treaty_status = 2;
			},
			//不同意
			cancelTreaty() {
				//退出程序
				// plus.runtime.quit();
			},
			//查看平台协议
			getTreaty(e) {
				var id = e.currentTarget.dataset.id;
				var path = '/pages/Component/Module/Login/treaty/index?id=' + id;
				ikz.nav(path, 'n', '');
			},

			//请求页面数据
			getList() {

				var path = '/Supply/Wechat/Public/indexPage';
				var data = {
					longitude: this.longitude,
					latitude: this.latitude
				};
				ikz.get(path, data, res => {
					if (res.data.status == 'success') {

					} else {
						uni.showModal({
							title: '提示',
							content: '服务器繁忙，请稍后再试',
							showCancel: false,
							success: function(res) {}
						});
					}
					// if(that.pull_status){
					// 	this.$emit("change",'pull');
					// }
				});
			},


			//跳转至招聘中心
			getRecriut() {
				let url = '/pages/Component/Module/Demand/Program/Recruit/index';
				ikz.nav(url, 'n');
			},

		}
	};
</script>

<style scoped>
	.ikz-top-bg {
		position: fixed;
		top: 0px;
		left: 0px;
	}

	.ikz-top-bg-img {
		width: 100%;
		height: 200rpx;
	}

	.ikz-banner-box {
		position: relative;
		width: 95%;
		margin: 15rpx auto 0px;

	}

	.ikz-location {
		box-sizing: border-box;
		position: absolute;
		top: 30rpx;
		left: 50rpx;
		display: flex;
		align-items: center;
		padding: 10rpx 40rpx 10rpx 30rpx;
		background: rgba(000, 000, 000, 0.3);
		color: #fff;
		border-radius: 70rpx;
		font-size: 25rpx;


	}

	.ikz-location-img {
		width: 40rpx;
		height: 40rpx;
		margin-right: 10rpx;
	}

	/* ad */
	.ikz-ad {
		width: 95%;
		margin: 30rpx auto 0;

	}

	.ikz-ad-img {
		width: 100%;
		height: 150rpx;
	}

	/* ad */
</style>
